from PIL import Image, ImageOps


def expandFix(file:str):
    img = Image.open(file)
    width, height = img.size
    border_width, border_height = 0, 0
    if width % 2 != 0:
        border_width = 1
    if height % 2 != 0:
        border_height = 1

    # 扩展图像
    border = (0,0,border_width,border_height)  # 边框宽度
    img = ImageOps.expand(img, border=border, fill=(0, 0, 0, 0))        
    return img


def cropFix(file:str):
    img = Image.open(file)
    width , height = img.size
    left = 0
    top = 0
    right = width
    bottom = height
    if width % 2 != 0:
        right = width - 1
    if height % 2 != 0:
        bottom = height - 1
    crop_area = (left, top, right, bottom)
    img = img.crop(crop_area)
    return img


def scallFix(file:str):
    img = Image.open(file)
    width , height = img.size
    if width % 2 != 0:
        width = width - 1
    if height % 2 != 0:
        height = height - 1
    img = img.resize((width,height))
    return img